<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var sum = function (nums, target) {
            const map = new Map()
            for (let i = 0; i < nums.length; i++) {
                const complement = target - nums[i]
                if (map.has(complement)) {
                    return [map.get(complement), i]
                } else {
                    map.set(nums[i], i)
                }
            }
            return []
        }


        function debounce(func, wait, immediate) {
            let timeout;
            return function () {
                if (timeout) clearTimeout(timeout)
                if (immediate) {
                    var callNow = !timeout
                    timeout = setTimeout(async () => {
                        timeout = null
                    }, wait);
                    if (callNow) func.apply(this, arguments)

                } else {
                    timeout = setTimeout(async () => {
                        func.apply(this, args)
                    }, wait);
                }
            }
        }

        function debounce(func, wait, immediate) {
            let timeout
            return function () {
                if (timeout) {
                    clearTimeout(timeout)
                }
                if (immediate) {
                    var callNow = !timeout
                    timeout = setTimeout(async () => {
                        timeout = null
                    }, wait);
                } else {
                    timeout = setTimeout(async () => {
                        func.apply(this,arguments)
                    }, wait);
                }
            }
        }


    </script>
</body>

</html>